package com.bbx.flink.demo.windowfuncation;

import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.api.common.functions.ReduceFunction;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.windowing.time.Time;
import org.apache.flink.streaming.api.windowing.windows.TimeWindow;
import sun.awt.SunHints;

public class ReduceFuncationDemo {

    public  static void main(String [] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.socketTextStream("192.168.10.131",10003)
                .map((MapFunction<String, Integer>) value -> Integer.parseInt(value))
                .keyBy(i->i%2)
                .timeWindow(Time.minutes(2))
                .reduce((ReduceFunction<Integer> ) (v1,v2) ->{
                   return v1+v2;
                }).print();
        env.execute();
    }
}
